<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('投资基金') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('基金简称')" prop="fundName">
        <el-input v-model="queryParams.fundName" :placeholder="$t('基金简称')" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="investFundInfos" border>
      <el-table-column :label="$t('基金简称')" align="center" prop="fundName" show-overflow-tooltip min-width="200">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{ path:'/fund/fundBasehome', query: { id: scope.row.fundId }}"
            class="link_a"
          >{{ scope.row.fundName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金总规模') + $t('金额单位')" prop="fundTotalScale" align="center" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.fundTotalScale, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金实缴金额') + $t('金额单位')" prop="fundTotalPaidScale" align="center" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.fundTotalPaidScale, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金估值') + $t('金额单位')" prop="fundTotalPaidScale" align="center" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.fundValuation, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('币种')" align="center" prop="currency">
        <template slot-scope="scope">
          <span>{{ getDictVaule('currency', scope.row.currency) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('认缴时间')" prop="timeSubscription" align="center" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.timeSubscription) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('认缴金额') + $t('金额单位')" prop="subscribedAmount" align="center" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.subscribedAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('认缴比例(%)')" prop="subscriptionRatio" align="center" show-overflow-tooltip min-width="100" />
      <el-table-column :label="$t('实缴金额') + $t('金额单位')" prop="paidAmount" align="center" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span class="money-text"><el-link type="primary" @click="showPaidAmount(scope.row)">{{ moneyFormat(scope.row.paidAmount, 'w') }}</el-link></span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('缴款比例(%)')" prop="paidRatio" align="center" show-overflow-tooltip min-width="100" />
      <el-table-column :label="$t('所占估值')+ $t('金额单位')" prop="valuation" align="center" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.valuation, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('分配总额')+ $t('金额单位')" prop="total" align="center" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <!--          <span>{{ moneyFormat(scope.row.total, 'w') }}</span>-->
          <span class="money-text"><el-link type="primary" @click="showTotal(scope.row)">{{ moneyFormat(scope.row.total, 'w') }}</el-link></span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogView" append-to-body>
      <fundLpPaymentViewList ref="fundLpPaymentViewList" />
    </el-dialog>
    <el-dialog :title="$t(title2)" :visible.sync="formOpen2" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogView" append-to-body>
      <fundFpDetailsList ref="fundFpDetailsList" />
    </el-dialog>
  </div>
</template>

<script>
import { findInvestFundInfo } from '@/api/fund/lpBase/lpBase'
import fundLpPaymentViewList from '@/views/fund/lpPayment/fundLpPaymentViewList'
import fundFpDetailsList from '@/views/fund/fp/fundFpDetailsList'

export default {
  components: {
    fundLpPaymentViewList,
    fundFpDetailsList
  },
  data() {
    return {
      title: '出资人缴款',
      // 是否显示弹出层
      formOpen: false,
      title2: '分配总额',
      // 是否显示弹出层
      formOpen2: false,
      total: 0,
      queryParams: {
        id: this.$route.query.lpId,
        fundName: undefined,
        pageNum: 1,
        pageSize: 10
      },
      loading: false,
      investFundInfos: [],
      dict: {
        currency: []
      }
    }
  },
  mounted() {
    this.initDict()
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      findInvestFundInfo(this.queryParams).then(response => {
        this.investFundInfos = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterange = []
      this.resetForm('queryForm')
      this.queryHandle()
    },
    initDict() {
      // 性别
      this.getDicts('currency').then(response => {
        this.dict.currency = response.data
      })
    },
    getDictVaule(listName, key) {
      const list = this.dict[listName]
      for (let i = 0; i < list.length; i++) {
        const dict = list[i]
        if (dict.dictValue === key) {
          return dict.dictLabel
        }
      }
    },
    showPaidAmount(row) {
      this.$nextTick(() => {
        this.formOpen = true
        const data = { lpId: this.$route.query.lpId, fundId: row.fundId }
        setTimeout(() => {
          this.$refs.fundLpPaymentViewList.getList(data)
        })
      })
    },
    showTotal(row) {
      console.log(row)
      this.$nextTick(() => {
        this.formOpen2 = true
        const data = { lpId: this.$route.query.lpId, fundId: row.fundId }
        setTimeout(() => {
          this.$refs.fundFpDetailsList.getList(data)
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
